package com.um.jdy.ykc.command;

import com.um.jdy.ykc.model.GetCard;
import com.um.jdy.ykc.utils.RadixsUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 离线卡数据查询应答（充电桩->运营平台）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd47QueryCardsResponse extends YkcCommand {

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 物理卡号：8个字节+1个字节
     */
    private List<GetCard> cardList;

    public Cmd47QueryCardsResponse() {
        this.command = RadixsUtil.hexToInteger("47");
    }

    @Override
    public void parseBytes(byte[] bytes){
        super.parseBytes(bytes);
        this.cardList = new ArrayList<>();
        code = RadixsUtil.bytesToHexString(readBytes(data,0,7));
        int length = (data.length - 7) / 9;

        int start = 7;
        for(int index = 0;index < length;index ++){

            GetCard item = new GetCard();
            item.setCode(RadixsUtil.bytesToHexString(readBytes(data,start,8)));
            item.setStatus(RadixsUtil.byteToInteger(data[start+8]));
            cardList.add(item);

            start += 9;
        }

        code = RadixsUtil.getCode(code);
    }
}
